package com.sharp.core.raytrace;

import java.util.ArrayList;
import java.util.List;

import com.sharp.core.math.Matrix;
import com.sharp.core.math.Transformations;
import com.sharp.core.math.UnVec3;
import com.sharp.core.math.Vec3;
import com.sharp.core.math.Vectors3D;
import com.sharp.core.math.primitives.CameraPlane;
import com.sharp.core.math.primitives.Object3D;
import com.sharp.core.math.primitives.Primitive;

public class Camera extends Object3D {

	private int startX, startY;
	private int width;
	private int height;
	private int fov;
	private CameraPlane plane;
	private float z;
	private Vec3 dir;
	private float dirLen;
	
	
	public Camera(int startX, int startY, int width, int height, int fov) {
		this.startX = startX;
		this.startY = startY;
		this.width = width;
		this.height = height;
		this.fov = fov;
		
		plane = new CameraPlane(width, height, fov, 1.0f);
		z = 1.0f;
		this.dir = new Vec3(0, 0, 1.0f);
		this.dirLen = dir.length();
	}
	
	@Override
	public void transform(Matrix m) {
	}
	
	public void rotate(Matrix m) {
		m.transform(dir);
		plane.transform(m);
	}
	
	public void forward(float v) {
		Vec3 move = Vectors3D.multiply(dir, v);
		getPos().add(move);
		plane.getPos().add(move);
	}
	
	public void strafe(float v) {
		Matrix m = Transformations.rotateAboutY(90);
		Vec3 move = new Vec3(dir);
		m.transform(move).multiply(v);
		getPos().add(move);
		plane.getPos().add(move);
	}
	
	public float getDirLength() {
		return dirLen;
	}	

	
	public int getStartX() {
		return startX;
	}

	public void setStartX(int startX) {
		this.startX = startX;
	}

	public int getStartY() {
		return startY;
	}

	public void setStartY(int startY) {
		this.startY = startY;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getFov() {
		return fov;
	}

	public void setFov(int fov) {
		this.fov = fov;
	}

	public CameraPlane getPlane() {
		return plane;
	}

	public void setPlane(CameraPlane plane) {
		this.plane = plane;
	}

	public float getZ() {
		return z;
	}

	public void setZ(float z) {
		this.z = z;
	}

	public UnVec3 getDir() {
		return dir;
	}

	public void setDir(Vec3 dir) {
		this.dir = dir;
	}
}
